import { createRouter, createWebHistory } from 'vue-router'
// createRouter:创建 router 实例对象
// createWebHistory: 创建 history 路由模式
import Layout from '@/views/Layout/index.vue'
import Home from '@/views/Home/index.vue'
const router = createRouter({
  history: createWebHistory((import.meta as any).env.BASE_URL),
  routes: [
    {
      path:'/',
      component:Layout,
      children:[
        {
          path:'',  // 默认展示
          component:Home
        },
        {
          path:'/category/:id',
          component: ()=>import('@/views/Category/index.vue')
        },
        {
          path:'/category/sub/:id', // 二级分类
          name:'categorysub',
          component: ()=>import('@/views/SubCategory/index.vue')
        },
        {
          path:'/detail/:id',
          component: ()=>import('@/views/Detail/index.vue')
        },
        {
          path:'cartlist',
          component:()=>import('@/views/CartList/index.vue')
        },
        { // 配置会员中心二级路由 + 三级路由
          path: '/member',
          component: ()=>import('@/views/Member/index.vue'),
          children: [
            {
              path: 'order', // 订单信息  
              component:()=>import('@/views/Member/components/UserOrder.vue')
            },
            {
              path: '',  // 个人中心  此处为空可以直接在二级路由中显示该页面
              component: ()=>import('@/views/Member/components/UserInfo.vue')
            }
          ]
        },
        {
          path:'/checkout',
          component: ()=>import('@/views/Checkout/index.vue')
        },
        {
          path:'pay',
          component: ()=>import('@/views/pay/index.vue')
        },
        {
          path:'paycallback',
          component:()=>import('@/views/pay/PayBack.vue')
        }
      ]
    },
    {
      path:'/login',
      component: ()=>import('@/views/Login/index.vue'),
    }
  ],
  // 路由行为定制
  scrollBehavior () {
    return {top:0}
  }
})

export default router
